﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="ZX.Web.UI.Controls.ListPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../../Scripts/JQuery_zTree_v3.3/css/zTreeStyle/zTreeStyle.css" rel="stylesheet"
        type="text/css" />        <link href="../../Scripts/JQuery_zTree_v3.3/css/demo.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/reset-fonts-grids/reset-fonts-grids.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/tabview/assets/skins/sam/tabview.css" />
    <link href="../../Styles/aui-css/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        #yui-content
        {
            height: 500px;
            border: 0px;
        }
        
        #btnOrgBarEdit
        {
        }
        
        #btnOrgBarSave
        {
        }
        
        .aui-icon-align-move
        {
            background: url(/styles/aui-css/img/shape_move_back.png) left no-repeat;
            height: 17px;
            width: 17px;
        }
        
        
        .aui-icon-align-add
        {
            background: url(/styles/aui-css/img/newspaper_plus.png) left no-repeat;
            width: 17px;
            height: 17px;
            border: 0px;
        }
        .aui-icon-align-edit
        {
            background: url(/styles/aui-css/img/article_edit.png) left no-repeat;
            width: 17px;
            height: 17px;
            border: 0px;
        }
        .aui-icon-align-copy
        {
            background: url(/styles/aui-css/img/page_2_copy.png) left no-repeat;
            width: 17px;
            height: 17px;
            border: 0px;
        }
        
        .aui-icon-align-cancel
        {
            background: url(/styles/aui-css/img/150.png) left no-repeat;
            width: 17px;
            height: 17px;
            border: 0px;
        }
<%--        .aui-icon-align-manager
        {  
            background: url(/styles/aui-css/img/3.jpg) left no-repeat;
            width: 17px;
            height: 17px;
            background-position: -395px -92px;
            border: 0px;
        }
        --%>
        .aui-icon-align-manager
        {  
            background: url(/styles/aui-css/img/3.jpg) left no-repeat;
            width: 17px;
            height: 17px;
            background-position:  -433px -35px;
            border: 0px;
        }

        
        .aui-icon-align-batchadd
        {
            background: url(/styles/aui-css/img/newspaper_add.png) left no-repeat;
            height: 17px;
            border: 0px;
        }
        
        #PostTable table
        {
            width: 100%;
            border: 1px;
        }
        #PostTable #PostThead
        {
            border: 1px solid #4169e1;
        }
        #PostTable #PostThead tr
        {
            height: 25px;
        }
        #PostTable #PostThead th
        {
            border: 1px solid #ccc;
            background: #e4e7e2;
            text-align: center;
            font-weight: bold;
            font-size: 14px;
            height: 17px;
            padding: 2px;
        }
        
        #PostTable #PostTbody td
        {
            border: 1px solid #ccc;
            height: 17px;
            padding: 2px;
        }
        
        #PostTable #PostTbody tr
        {
            height: 25px;
            cursor: hand;
        }
        
        #PostTbody .tr_1
        {
            background-color: #f0ffff;
        }
        
        #PostTbody .tr_0
        {
            background-color: #fff;
        }
        
        
        .yui-layout-hd
        {
            height: 32px;
            vertical-align: middle;
        }
        
        .selected
        {
            background: #6495ed;
        }
        
        h1
        {
            font-size:12px;
        }
    </style>

    <link href="../../ConfigData/Ctrl.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/layout/assets/skins/sam/layout.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/layout/layout-min.js"></script>
    <script src="../../Scripts/yui_2.9.0/build/tabview/tabview-min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../Scripts/colResizable-1.3.min.js"></script>
    <script src="../../Scripts/jquery.fbmodel.js" type="text/javascript"></script>
    <script src="../../Scripts/JQuery_zTree_v3.3/js/jquery.ztree.core-3.3.js" type="text/javascript"></script>
    <script src="../../Scripts/JQuery_zTree_v3.3/js/jquery.ztree.excheck-3.3.js" type="text/javascript"></script>
    <script src="../../Scripts/JQuery_zTree_v3.3/js/jquery.ztree.exedit-3.3.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../Scripts/ArrayToJson.js"></script>
    <script src="/Extend/AjaxData/DataTableJsonList.aspx?entity=V_Dept&type=2" type="text/javascript"></script>
    <script src="../../ConfigData/jquery.DeptSelect.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.action.js" type="text/javascript"></script>
</head>

 
<body class="yui-skin-sam">
    <div id="left">
        <ul class='ztree' id='orgTree' style="width: 100%; height: 100%; border: 0px; margin: -5px;">
        </ul>
    </div>
    <div id="center" style="height: 100%">
        <div id="demo" class="yui-navset" style="height: 100%">
            <ul id="yui-nav" class="yui-nav">
                <li class="selected"><a href="#tab1"><em>组织结构信息</em></a></li>
                <li><a href="#tab2"><em>岗位信息</em></a></li>
                <li><a href="#tab3"><em>组织结构图</em></a></li>
            </ul>
            <div id="yui-content" class="yui-content">
                <div id="tab1">
                    <div id="radiogroup2" class="aui-btn-group aui-btn-group-radio">
                        <button class="aui-btn" title="新增" id='btnNew'>
                            <i class="aui-icon-align-add"></i>
                        </button>
                        <button class="aui-btn" title="编辑" id='btnEdit'>
                            <i class="aui-icon-align-edit"></i>
                        </button>
                        <button class="aui-btn" title="移动部门" id='btnMove'>
                            <i class="aui-icon-align-move"></i>
                        </button>
                        <button class="aui-btn" title="复制部门" id='btnCopy'>
                            <i class="aui-icon-align-copy"></i>
                        </button>
                    </div>
                    <iframe id="Department" src="/Extend/AutoLoadForm.aspx?read=true&entity=DatDepartment&id=333fe8ed-ca2a-497a-a88c-3bb4fb3a1a57"
                        frameborder="0" style="height: 100%; width: 100%"></iframe>
                </div>
                <div id="tab2">
                    <div id="radiogroup1" class="aui-btn-group aui-btn-group-radio">
                        <button class="aui-btn" title="修改" id="btnEditPost">
                            <i class="aui-icon-align-edit"></i>
                        </button>
                        <button class="aui-btn" title="批增" id="btnBatchAdd">
                            <i class="aui-icon-align-batchadd"></i>
                        </button>
                        <button class="aui-btn" title="复制到" id="btnCopyPost">
                            <i class="aui-icon-align-copy"></i>
                        </button>
                        <button class="aui-btn" title="设为主管岗位" id="btnSetMangerPost">
                            <i class="aui-icon-align-manager"></i>
                        </button>
                        <button class="aui-btn" title="取消主管岗位" id="btnCancelMangerPost">
                            <i class="aui-icon-align-cancel"></i>
                        </button>
                    </div>
                    <div id="PostTable">
                        <table id="PostTableHead">
                            <thead id="PostThead">
                                <tr id="{1}">
                                    <th style="width: 20px">
                                        <input type="checkbox" />
                                    </th>
                                    <th style="width: 200px">
                                        职位名称
                                    </th>
                                    <th style="width: 150px">
                                        部门名称
                                    </th>
                                    <th style="width: 100px">
                                        职务名称
                                    </th>
                                    <th style="width: 100px">
                                        职务类型
                                    </th>
                                    <th style="width: 20px" title='是否为主管岗位'>
                                        []
                                    </th>
                                    <th style="width: 200px">
                                        上级职位
                                    </th>
                                    <th style="width: 40px">
                                        职级
                                    </th>
                                    <th>
                                    </th>
                                </tr>
                            </thead>
                        </table>
                        <table id="PostTableDetail">
                            <tbody id="PostTbody">
                            </tbody>
                        </table>
                    </div>
                </div>
                <div id="tab3" style="height: 100%">
                    <iframe id="_OrgChart" src="" frameborder="0" style="height: 100%; width: 100%">
                    </iframe>
                </div>
            </div>
        </div>

<!---- dialog ---->
        <div id="dialogArea" style=" z-index: 100; border: 1px solid #bbb; display:none ">
            <div class="yui-pe-title" style="height: 25px; border-bottom: 1px solid #bbb; top: 0px;
                right: 0px; left: 0px;font-size:14px; font-weight:bold; padding:1px;">
                岗位批量新增 
            </div>
            <div class="yui-pe-title" style="height: 25px; border-bottom: 1px solid #bbb; top: 0px;
                right: 0px; left: 0px;font-size:14px; font-weight:bold; padding:1px;">
                <input  id="sVALUE"  style="padding:1px"/> <input id="btnSearch" class="aui-btn" style="padding:0px 1px 0px 1px; margin-left:-3px;margin-top:-3px;" value="搜" type="button" />
            </div>
            <div class="yui-pe-content" style="height: 340px; border-top: 1px solid #bbb; bottom: 0px;
                right: 0px; left: 0px;">
                <div style="width:270px;height: 340px; border-left: 1px solid #bbb; float:right">
                <ul class='ztree' id='postTreeRight' style="width: 260px; height: 334px; border: 0px; margin: 0px; overflow:auto">
                </ul>
                </div>
                <div style="width:270px;height: 340px; border-right: 1px solid #bbb; float:left"><div style="height:340px;">
                        <ul class='ztree' id='postTreeLeft' style="width: 260px; height: 334px; border: 0px; margin: 0px; overflow:auto">
                        </ul>
                </div></div>
                      <div style="height: 280px; bottom: 0px;
                right: 0px; vertical-align:middle;  float:left; width:40px; margin-left:6px"><div style="margin-top:120px;text-align:center"><button  class="aui-btn">>></button>
                            <button  class="aui-btn"><<</button></div></div>
            </div>
            <div class="yui-pe-bottom" style="border-top: 1px solid #ddd; bottom: 0px;
                right: 0px; left: 0px; text-align: right; padding:1px; height:35px">
                <button id="btnOK" class="aui-btn">
                    确定</button>
                <button id="btnCancel" class="aui-btn">
                        取消</button>
            </div>
        </div>

       <div id="dialogPostSetting" style=" z-index: 100; border: 1px solid #bbb; display:none ">
            <div class="yui-pe-title" style="height: 25px; border-bottom: 1px solid #bbb; top: 0px;
                right: 0px; left: 0px;font-size:14px; font-weight:bold; padding:1px;">
                岗位信息设置
            </div>
            <div class="yui-pe-content" style="height: 340px; border-top: 1px solid #bbb; bottom: 0px;
                right: 0px; left: 0px;">
                  <iframe id="_DatPost" src="" frameborder="0" style="height: 100%; width: 100%">
                  </iframe>
            </div>
            <div class="yui-pe-bottom" style="border-top: 1px solid #ddd; bottom: 0px;
                right: 0px; left: 0px; text-align: right; padding:1px; height:35px">
                <button id="btnOK_01" class="aui-btn">
                    确定</button>
                <button id="btnCancel_01" class="aui-btn">
                        取消</button>
            </div>
        </div>

        <div id="dialogDeptSetting" style=" z-index: 100; border: 1px solid #bbb; display:none ">
            <div class="yui-pe-title" style="height: 25px; border-bottom: 1px solid #bbb; top: 0px;
                right: 0px; left: 0px;font-size:14px; font-weight:bold; padding:1px;">
                组织结构信息设置
            </div>
            <div class="yui-pe-content" style="height: 420px; border-top: 1px solid #bbb; bottom: 0px;
                right: 0px; left: 0px;">
                  <iframe id="_Department" src="" frameborder="0" style="height: 100%; width: 100%">
                  </iframe>
            </div>
            <div class="yui-pe-bottom" style="border-top: 1px solid #ddd; bottom: 0px;
                right: 0px; left: 0px; text-align: right; padding:1px; height:35px">
                <button id="btnOK_02" class="aui-btn">
                    确定</button>
                <button id="btnCancel_02" class="aui-btn">
                        取消</button>
            </div>
        </div>

<!---- dialog ---->
        <div id="dialogDeptSelect" style=" z-index: 100; border: 1px solid #bbb; display:none ">
            <div class="yui-pe-title" style="height: 25px; border-bottom: 1px solid #bbb; top: 0px;
                right: 0px; left: 0px;font-size:14px; font-weight:bold; padding:1px;" id="selectTitle">
                组织结构信息设置
            </div>
            <div class="yui-pe-content" style="height: 90px; border-top: 1px solid #bbb; bottom: 0px;
                right: 0px; left: 0px; padding:25px;">
                    <input type="text" SValue="" SText="" id="targetDept" ctrlType="Dept" />
            </div>
            <div class="yui-pe-bottom" style="border-top: 1px solid #ddd; bottom: 0px;
                right: 0px; left: 0px; text-align: right; padding:1px; height:35px">
                <button id="btnOK_03" class="aui-btn">
                    确定</button>
                <button id="btnCancel_03" class="aui-btn">
                        取消</button>
            </div>
        </div>


    </div>
</body>
</html>
<script type="text/javascript">
    /* 树 */
    var setting = { 
        	edit: {
        			drag: {
        				autoExpandTrigger: true,
        				prev: dropPrev,
        				inner: dropInner,
        				next: dropNext
        			},
        			enable: true,
        			showRemoveBtn: false,
        			showRenameBtn: false,
        							    editNameSelectAll: false

        		},
        data: {
            key: {
                title: "t"
            },
            simpleData: {
                enable: true
            }
        },
        callback: {
            beforeClick: beforeClick,
            onClick: onClick,
            beforeDrag: beforeDrag,
            beforeDrop: beforeDrop,
            beforeDragOpen: beforeDragOpen,
            onDrag: onDrag,
            onDrop: onDrop,
            onExpand: onExpand
        }
    };


    var DutyInfosetting = {
        edit: {
            enable: true,
            showRemoveBtn: false,
            showRenameBtn: false
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
            beforeDrag: beforeDrag,
            beforeDrop: beforeDrop
        }
    };

    var log, className = "dark";
    function beforeClick(treeId, treeNode, clickFlag) {
        className = (className === "dark" ? "" : "dark");
        return (treeNode.click != false);
    }

    var _treeNode = null;
    function onClick(event, treeId, treeNode, clickFlag) {
        $("#Department")[0].src = "/Extend/AutoLoadForm.aspx?r=" + Math.random() + "&read=true&entity=DatDepartment&id=" + treeNode.id;
        $("#_OrgChart")[0].src = "/Extend/OrgChart.aspx?r="+Math.random()+"&showOrg=true&deptID=" + treeNode.id;
        GetPostData(treeNode.id);
        _CurDeptID = treeNode.id;
        _CurDeptName = treeNode.name;
        fnSetDutyInfoItem();
        _treeNode = treeNode;
        //$("#"+defaults.CtrolID).val(treeNode.name);
        //setValue(treeNode.id);
        //hide();
    }

    function AddNewNode(id, deptName) {
        var zTree = $.fn.zTree.getZTreeObj("orgTree");
        zTree.addNodes(_treeNode, { id: id, pId: _treeNode.id, name:deptName }); 
    }
    



    function addHoverDom(treeId, treeNode) {
        //debugger
        var sObj = $("#" + treeNode.tId + "_span");
        if (treeNode.editNameFlag || $("#addBtn_" + treeNode.id).length > 0) return;
        var addStr = "<span class='button add' id='addBtn_" + treeNode.id
				+ "' title='add node' onfocus='this.blur();'></span>";
        sObj.after(addStr);
        var btn = $("#addBtn_" + treeNode.id);
        if (btn) btn.bind("click", function () {
            var zTree = $.fn.zTree.getZTreeObj("orgTree");
            zTree.addNodes(_treeNode, { id: (100 + newCount), pId: _treeNode.id, name: "new node" + (newCount++) });
            return false;
        });
    };
    function beforeDragOpen(treeId, treeNode) {
        //        autoExpandNode = treeNode;
        //        return true;
    }

    function beforeDrag(treeId, treeNodes) {
        //debugger
        //        for (var i = 0, l = treeNodes.length; i < l; i++) {
        //            if (treeNodes[i].drag === false) {
        //                return false;
        //            }
        //        }
        //        return true;
    }
    function beforeDrop(treeId, treeNodes, targetNode, moveType) {
        //debugger
        //return targetNode ? targetNode.drop !== false : true;
    }

    function dropPrev(treeId, nodes, targetNode) {
        //        var pNode = targetNode.getParentNode();
        //        if (pNode && pNode.dropInner === false) {
        //            return false;
        //        } else {
        //            for (var i = 0, l = curDragNodes.length; i < l; i++) {
        //                var curPNode = curDragNodes[i].getParentNode();
        //                if (curPNode && curPNode !== targetNode.getParentNode() && curPNode.childOuter === false) {
        //                    return false;
        //                }
        //            }
        //        }
        //        return true;
    }
    function dropInner(treeId, nodes, targetNode) {
        //        if (targetNode && targetNode.dropInner === false) {
        //            return false;
        //        } else {
        //            for (var i = 0, l = curDragNodes.length; i < l; i++) {
        //                if (!targetNode && curDragNodes[i].dropRoot === false) {
        //                    return false;
        //                } else if (curDragNodes[i].parentTId && curDragNodes[i].getParentNode() !== targetNode && curDragNodes[i].getParentNode().childOuter === false) {
        //                    return false;
        //                }
        //            }
        //        }
        //        return true;
    }
    function dropNext(treeId, nodes, targetNode) {
        //        var pNode = targetNode.getParentNode();
        //        if (pNode && pNode.dropInner === false) {
        //            return false;
        //        } else {
        //            for (var i = 0, l = curDragNodes.length; i < l; i++) {
        //                var curPNode = curDragNodes[i].getParentNode();
        //                if (curPNode && curPNode !== targetNode.getParentNode() && curPNode.childOuter === false) {
        //                    return false;
        //                }
        //            }
        //        }
        //        return true;
    }

    function onDrag(event, treeId, treeNodes) {
        ///className = (className === "dark" ? "" : "dark");
        ///showLog("[ " + getTime() + " onDrag ]&nbsp;&nbsp;&nbsp;&nbsp; drag: " + treeNodes.length + " nodes.");
    }
    function onDrop(event, treeId, treeNodes, targetNode, moveType, isCopy) {
        ///className = (className === "dark" ? "" : "dark");
        ///showLog("[ " + getTime() + " onDrop ]&nbsp;&nbsp;&nbsp;&nbsp; moveType:" + moveType);
        ///showLog("target: " + (targetNode ? targetNode.name : "root") + "  -- is " + (isCopy == null ? "cancel" : isCopy ? "copy" : "move"))
    }
    function onExpand(event, treeId, treeNode) {
        //        if (treeNode === autoExpandNode) {
        //            className = (className === "dark" ? "" : "dark");
        //            showLog("[ " + getTime() + " onExpand ]&nbsp;&nbsp;&nbsp;&nbsp;" + treeNode.name);
        //        }
    }

    (function () {
        var Dom = YAHOO.util.Dom,
        Event = YAHOO.util.Event;

        Event.onDOMReady(function () {
            var layout = new YAHOO.widget.Layout({
                units: [
                //{ position: 'top', height: 35, body: 'toolbar', gutter: '1 1 1 1', scroll: null, zIndex: 2 },
                {position: 'left', header: '', width: 220, body: 'left', gutter: '1 1 1 1', scroll: true, zIndex: 1, resize: true },
                { position: 'center', body: 'center', gutter: '1 1', scroll: true }
                //{ position: 'bottom', height: 35, body: 'bottom', gutter: '1 1' }
            ]
            });
            layout.render();
        });
        var tabView = new YAHOO.widget.TabView('demo');
        setTimeout(
        function () {
            $("#tab1").height($("#center").height() - 20);
            $("#tab2").height($("#center").height() - 20);
            $("#tab3").height($("#center").height() - 20);
        }, 100
        );
    })();

    function setHeight() {
        $("#tab1").height($("#demo").height() - 40);
        $("#tab2").height($("#demo").height() - 40);
        $("#tab3").height($("#demo").height() - 40);
    }

    //$("body").resize(setHeight);
    $(document).ready(function () {
        $.get("/Extend/AjaxData/DataTableJsonList.aspx?r=" + Math.random() + "&entity=V_hrOrgPostEmp&type=0&condition=flag='1d'",
            function (d, t) {
                var data = eval("(" + d + ")");
                // debugger
                // alert(data.rows.length);
                var _temp = [];
                $.each(data.rows, function (e) {
                    //var a = e;
                    _temp.push($.extend(data.rows[e], { drag: true }));
                });
                //debugger
                $.fn.zTree.init($("#orgTree"), setting, _temp);

                //$.fn.zTree.init($("#postTree"), setting, _temp);
                //$.fn.zTree._z.data
                SetDrop();
            });
            setTimeout(fnSetDutyInfoItem ,200);



        //测试窗体变更
        //$(window).resize(function () { alert($(document).height()); });



        /*高为屏幕的高*/


        });

        function fnSetDutyInfoItem() {
        //debugger
         var keyVALUE = $("#sVALUE").val();
         var url = "/Extend/AjaxData/DataTableJsonList.aspx?entity=V_hrDutyInfo&type=0&order=name&condition=(pId='00000000-0000-0000-0000-000000000000' or name like  '%" +encodeURI(keyVALUE) + "%')";
         if ( _CurDeptID !=undefined && _CurDeptID != "" ) {
             url = "/Extend/AjaxData/DataTableJsonList.aspx?entity=V_hrDutyInfo&type=0&order=name&condition=(pId='00000000-0000-0000-0000-000000000000' or name like  '%" +encodeURI(keyVALUE) + "%') and " + decodeURI("id not in (select PositionID from DatPost where DeptID='" + _CurDeptID + "')&r=" + Math.random());
         }

        $.get(url,
        function (d, t) {
            var data = eval("(" + d + ")");
            // debugger
            // alert(data.rows.length);
            var _temp = [];
            $.each(data.rows, function (e) {
                //var a = e;
                _temp.push($.extend(data.rows[e], { drag: true }));
            });
            //debugger
            //$.fn.zTree.init($("#orgTree"), setting, _temp);

            $.fn.zTree.init($("#postTreeLeft"), DutyInfosetting, _temp);
            $.fn.zTree.init($("#postTreeRight"), DutyInfosetting);
            //$.fn.zTree._z.data
            //SetDrop();
        });
   }


    //用于对话框"确定"按钮的回调
    var _callBack = function (status) {
        //alert(FormulaData);
        //if (status == 1) {
        //$("#DataSource").val(FormulaData);
        //}
    }

    function SetDrop() {
        var zTree = $.fn.zTree.getZTreeObj("orgTree");
        //zTree.setting.edit.drag.isCopy = true;
        zTree.setting.edit.drag.isMove = true;
        //showCode(1, ['setting.edit.drag.isCopy = ' + isCopy, 'setting.edit.drag.isMove = ' + isMove]);

        zTree.setting.edit.drag.prev = true;
        zTree.setting.edit.drag.inner = true;
        zTree.setting.edit.drag.next = true;
    }

    var trHTML = '<tr id=\"data_row_{2}\"  class="tr{1}"><td style="width:20px; text-align:center"><input type="checkbox"/></td><td style="width:200px">职位名称</td><td style="width:150px">部门名称</td><td style="width:100px">职务名称</td><td style="width:100px">职务类型</td><td style="width:20px">{0}</td><td style="width:200px">上级职位</td><td style="width:40px">职级</td><td></td></tr>';
    function GetPostData(deptID) {
        $.get("/Extend/AjaxData/DataTableJsonList.aspx?entity=V_DatPost&type=0&condition=DeptID='" + deptID + "'&r="+Math.random(),
            function (d, t) {
                var trTbody = '';
                //debugger
                if (d == '{"total":0,"rows":}') {
                    $("#PostTbody").html(trTbody);
                    return;
                }
                var data = eval("(" + d + ")");
                Rows = data.rows;
                $.each(data.rows, function (o) {
                    var _r = (o / 2).toString().indexOf('.5') > 0 ? '_0' : '_1';
                    var _y = data.rows[o].PostLevel == 0 ? "<font color='red'>是</font>" : "否";
                    trTbody = trTbody + trHTML.replace("{_0}", data.rows[o].PostID)
                            .replace("职位名称", data.rows[o].PostName)
                            .replace("部门名称", data.rows[o].DeptName)
                            .replace("职务类型", data.rows[o].PhraseText)
                            .replace("职级", data.rows[o].PostRank)
                            .replace("职务名称", data.rows[o].Name)
                            .replace("{0}", _y)
                            .replace("上级职位", data.rows[o].ParentPositionName)
                            .replace("{1}", _r)
                            .replace("{2}", o);

                });
                $("#PostTbody").html(trTbody);
                $("#PostTbody tr").click(Selected);
            });
    }

    //const_DataFields = [{ key: 'ID', label: 'ID', width: 100, sortable: true, resizeable: true }, { key: 'iSun_Selected', label: '', width: 10, formatter: "checkbox" }, { key: 'SequenceNo', label: '顺序号', width: 50, sortable: true, resizeable: true }, { key: 'Name', label: '职务名称', width: 120, sortable: true, resizeable: true }, { key: 'DutyTypeName', label: '职务类型', width: 120, sortable: true, resizeable: true }, { key: 'Remark', label: '备注', width: 500, sortable: true, resizeable: true}],
    //const_DataColums = ['ID', 'iSun_Selected', 'SequenceNo', 'Name', 'DutyTypeName', 'Remark'],


    function fnLoginOut() {

    }

    //
    //生成部门Path
    function fnBuildDeptPath(parentid) {
        $.get("/Extend/AjaxData/DataAction.aspx?parentId=" + parentid + "&entity=dept&action=createDeptPath&r=" + Math.random(),
            function (d, t) {
                //alert(d);
            });
    }



    //
    //职位
    function fnBatchAddPost(json,fn) {
        $.get("/Extend/AjaxData/DataAction.aspx?entity=post&action=batchadd&json=" + json,
            function (d, t) {
                if (d == "1") {
                    alert("职位设置成功");
                    GetPostData(_CurDeptID);
                    $("#dialogArea").css({ "display": "none" });
                }
                if (fn) {
                    fn();
                }
            });
        }

    //
    //主管职位
    function fnSetManagerPost(postID) {
        $.get("/Extend/AjaxData/DataAction.aspx?entity=post&action=setmanagerpost&postid="+postID+"&r="+Math.random(),
        function (d) {
            if (d == "1") {
                alert("设置成功");
                GetPostData(_CurDeptID);
            }
        });
    }


    function fnCancelManagerPost(postID) {
        fnRunProc("sp_Sys_CancelManagerPost", postID,callBack);
        function callBack(data) {
            if (data.stuats == 1) {
                alert("执行成功");
                GetPostData(_CurDeptID);
            }
            else {
                alert("执行失败:" + data.msg);
            }
           
        }
    }

     
        
    
    // 相关按钮事件
    $(document).ready(function () {
        //fnBuildDeptPath('4970C90E-A6AD-48B9-BF4D-00CEC7FD3F6B');
        $("#btnSearch").click(fnSetDutyInfoItem);
        $("#btnNew").click(AddDept);
        $("#btnEdit").click(EditDept);
        $("#btnSave").click(SaveDept);
        $("#btnBatchAdd").click(function () {
            $("#dialogArea").css({ "position": "absolute", "z-index": "999999", "text-align": "center", "top": "70px", "left": "50px", "height": "435px", "width": "600px", "background": "#eee", "display": "" });
        });

        //
        $("#btnCancel").click(function () {
            $("#dialogArea").css({ "display": "none" });
            //fnSetDutyInfoItem();
        });

        //确定
        $("#btnOK").click(function () {
            //alert("OK");
            var items = $.fn.zTree.getZTreeObj("postTreeRight").getNodes();
            var _o = [];
            $.each(items, function (i) {
                _o.push({ PositionID: items[i].id, DeptID: _CurDeptID });
            });
            //debugger
            fnBatchAddPost(arrayToJson(_o));
            //fnSetDutyInfoItem();
        });
        $("#btnCancel_01").click(function () {
            $("#dialogPostSetting").css({ "display": "none" });
            //fnSetDutyInfoItem();
        });

        //确定
        $("#btnOK_01").click(function () {
            //alert("OK");
            SavePost();
            //fnSetDutyInfoItem();
        });

        $("#btnCancel_02").click(function () {
            $("#dialogDeptSetting").css({ "display": "none" });
            //fnSetDutyInfoItem();
        });

        //确定
        $("#btnOK_02").click(function () {
            //alert("OK");
            SaveDept();
            //fnSetDutyInfoItem();
        });

        var _bl = "";
        $("#btnMove").click(function () {
            _bl = "dept";
            $("#selectTitle")[0].innerHTML = "移动部到选定的部门";
            $("#dialogDeptSelect").css({ "position": "absolute", "z-index": "999999", "text-align": "center", "top": "70px", "left": "50px", "height": "200px", "width": "500px", "background": "#eee", "display": "" });
        });

        $("#btnCopyPost").click(function () {
            _bl = "post";
            $("#selectTitle")[0].innerHTML = "复制职位到选定部门";
            $("#dialogDeptSelect").css({ "position": "absolute", "z-index": "999999", "text-align": "center", "top": "70px", "left": "50px", "height": "200px", "width": "500px", "background": "#eee", "display": "" });
        });


        $("#btnCopy").click(function () {
            if (confirm("是否要复制选中的部门？\r\n复制的部门后和选中部门会生在同一级！\r\n并且仅复制二层的组织结构!")) {
                $.get("/Extend/AjaxData/DataAction.aspx?entity=dept&action=copydept&sourceID=" + _CurDeptID,
                    function (d) {
                        if (d == "1") {
                            alert("复制部门成功");
                            GetPostData(_CurDeptID);
                        }
                    });
            }
        });



        //部门选择项
        $("#btnOK_03").click(function () {
            var _sourceDeptID = _CurDeptID
            , _targerDeptID = $("#targetDept").attr("SValue");
            if (_bl == "dept") {
                fnMoveDept(_sourceDeptID, _targerDeptID);
            }
            else {
                fnCopyDeptPost(_sourceDeptID, _targerDeptID);
            }
            //fnSetDutyInfoItem();
        });


        $("#btnCancel_03").click(function () {
            $("#dialogDeptSelect").css({ "display": "none" });
        });

        ///设置主管岗位
        $("#btnSetMangerPost").click(function () {
            //alert("___");
            if (confirm("是否设置为主管岗位?")) {
                fnSetManagerPost(CureentRow.PostID);
            }
        });

        $("#btnCancelMangerPost").click(function () {
            //alert("___");
            if (confirm("是否取消主管岗位?")) {
                fnCancelManagerPost(CureentRow.PostID);
            }
        });

        


        $("#btnEditPost").click(function () {
            $("#_DatPost")[0].src = "/Extend/AutoLoadForm.aspx?entity=DatPost&id=" + CureentRow.PostID;
            $("#dialogPostSetting").css({ "position": "absolute", "z-index": "999998", "text-align": "center", "top": "70px", "left": "50px", "height": "400px", "width": "600px", "background": "#eee", "display": "" });
        });
    });

   

    /// ----------------------------------------------------
    var _CurDeptID = "";
    function AddDept() {
        $("#_Department")[0].src = "/Extend/AutoLoadForm.aspx?entity=DatDepartment&ParentID=" + _CurDeptID;
        $("#dialogDeptSetting").css({ "position": "absolute", "z-index": "999998", "text-align": "center", "top": "70px", "left": "10px", "height": "480px", "width": "650px", "background": "#eee", "display": "" });
    }

    function EditDept() {
        $("#_Department")[0].src = "/Extend/AutoLoadForm.aspx?entity=DatDepartment&id=" + _CurDeptID + "&r=" + Math.random();
        $("#dialogDeptSetting").css({ "position": "absolute", "z-index": "999998", "text-align": "center", "top": "70px", "left": "10px", "height": "480px", "width": "650px", "background": "#eee", "display": "" });
    }

    function SaveDept() {
        var editwindow = document.getElementById("_Department");
        if (editwindow) {
            editwindow.contentWindow.Save();
        }
        setTimeout(function () {
            $("#dialogDeptSetting").css({ "display": "none" });
        }, 20);
    }

    function SavePost() {
        var editwindow = document.getElementById("_DatPost");
        if (editwindow) {
            editwindow.contentWindow.Save();
        }
        setTimeout(function () {
            $("#dialogPostSetting").css({ "display": "none" });
        }, 20);
    }

    //移动部门
    function fnMoveDept(sourceDeptID,targetDeptID) {
        $.get("/Extend/AjaxData/DataAction.aspx?entity=dept&action=movedept&sourceID=" + sourceDeptID + "&parentID=" + targetDeptID,
        function (d) {
            if (d == "1") {
                alert("部门移动成功");
                //GetPostData(_CurDeptID);
            }
        });
    }

    //复制部门职位
    function fnCopyDeptPost(sourceDeptID, targetDeptID) {
        $.get("/Extend/AjaxData/DataAction.aspx?entity=post&action=copypost&sourceDeptID=" + sourceDeptID + "&targetDeptID=" + targetDeptID,
        function (d) {
            if (d == "1") {
                alert("职位复制成功!");
                GetPostData(_CurDeptID);
            }
        });
    }

    //复制部门
    function fnCopyDept(targetDeptID) {
        $.get("/Extend/AjaxData/DataAction.aspx?entity=dept&action=copydept&sourceID=" + sourceDeptID,
        function (d) {
            if (d == "1") {
                alert("设置成功");
                //GetPostData(_CurDeptID);
            }
        });
    }

    /// ----------------------------------------------------




    ///----------------------------------------------------
    //选定某条数据
    var SelectedIndex = 0,
        Rows = [],
        CureentRow = null,
        DutyInfoItems = []; //职务信息
    function Selected() {
        //alert("");
        var _this = this;
        SelectedIndex = 0;
        var trs1 = $("#PostTbody tr");
        trs1.find("td").removeClass("selected");
        $(_this).find("td").addClass("selected");
        trs1.each(function (em) {
            var _class = $(trs1[em]).attr("class");
            if (_class == undefined) {
                return;
            }
            if ($(_this).find("td").attr("class").indexOf("selected") > -1) {
                SelectedIndex = em;
            }
        });
        SelectedIndex = parseInt($(this).attr("id").replace("data_row_", ""));
        CureentRow = Rows[SelectedIndex];
        //alert(CureentRow.PostName);
    }
</script>
